//
//  ClassListModel.m
//  BOSS-SOOC
//
//  Created by apple on 16/8/19.
//  Copyright © 2016年 Gcx. All rights reserved.
//

#import "ClassListModel.h"
#import "ClassDetailModel.h"
#import "PlayerViewController.h"

@implementation ClassListModel

- (id)init{
    
    if (self = [super init]) {
        
        _sourceArr = [NSMutableArray array];
    }
    return self;
}

- (void)getListData:(long)page yxid:(NSString *)yxid{

    NSDictionary *dic = @{@"oauth_token":@"815bffb68e2ea44e38cf16a98a5a29a4",@"oauth_token_secret":@"8e84bc64f03d73b5c75406ef1d7349f7",@"page":[NSString stringWithFormat:@"%ld",page],@"pageCount":@10,@"yxid":yxid};
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:dic];
    
    SCHttpRequest*request = [[SCHttpRequest alloc]initWithApi:API_allNewCourse params:params];
    
    [self doPOSTConnect:request start:^(SCHttpRequest * _Nonnull req) {
        
    } success:^(SCHttpRequest * _Nonnull req, SCHttpResponse * _Nonnull resp) {
        
        NSLog(@"%@", resp.originalDictionary);
        
        NSArray *array = resp.originalDictionary[@"data"];
        
        /**
         *  page = 1 清空所有数据
         */
        if (page == 1) {
            
            [_sourceArr removeAllObjects];
        }
        
        for (NSDictionary *dic in array) {
            
            ClassDetailModel *model = [ClassDetailModel modelWithDic:dic];
            
            [_sourceArr addObject:model];
        }
        
        _succeedBlock(_sourceArr);
        
    } failure:^(SCHttpRequest * _Nonnull req, NSError * _Nonnull error) {
        
        _failBlock(error);
        
    } finish:^(SCHttpRequest * _Nonnull req, BOOL success) {
        
        [[NSNotificationCenter defaultCenter]postNotificationName:@"isClassListRefresh" object:nil];

    }];
}

- (void)detailWithListModel:(ClassDetailModel *)classModel WithViewController:(UIViewController *)superController{

    PlayerViewController *play = [[PlayerViewController alloc]initDataWithYxid:classModel.kcid];
    
    play.hidesBottomBarWhenPushed = YES;
    
    [superController.navigationController pushViewController:play animated:YES];
}

@end
